// 单个订单项类型
export interface OrderItem {
  body: string;
  categoriesTree: string; // 用竖线分隔的分类ID
  goodsCategory: string;
  goodsId: string;
  goodsName: string;
  outItemId: string;
  outSkuId: string;
  price: string; // 字符串形式的金额（建议后续可改为 number 或 Decimal）
  quantity: number;
}

// 主订单类型
export interface PaymentOrder {
  orderNum: string;      // 订单编号
  amount: string;        // 总金额（字符串形式）
  title: string;         // 订单标题/名称
  orderItems: OrderItem[]; // 订单项数组
  authCode?: string;     // 可选字段：授权码（根据业务决定是否必填）
}

export interface BasePayResponse {
  success: boolean;
  errorCode?: number;
  errorMessage?: string;
  showType?: number;
  diagnosisUrl?: string | null;
}

// 资金账单明细
export interface FundBill {
  fundChannel: string;
  amount: string;
}

// 优惠明细
export interface VoucherDetail {
  id: string;
  name: string;
  type: string;
  amount: string;
}

// 支付宝支付核心响应
export interface AlipayTradePayResponse {
  code: string;
  msg: string;
  subMsg: string | null;
  tradeNo: string;               // 支付宝交易号
  outTradeNo: string;            // 商户订单号
  buyerLogonId: string;          // 买家支付宝账号
  totalAmount: string;           // 订单金额
  receiptAmount: string;         // 实收金额
  buyerPayAmount: string;        // 买家付款金额
  pointAmount: string;          // 积分支付金额
  invoiceAmount: string;         // 开票金额
  gmtPayment: string | null;     // 交易支付时间
  fundBillList: FundBill[] | null; // 支付资金明细
  storeName: string | null;      // 门店名称
  discountGoodsDetail: string | null;
  buyerOpenId: string | null;
  buyerUserId: string;           // 买家支付宝用户ID
  voucherDetailList: VoucherDetail[] | null;
  mdiscountAmount: string | null;
  discountAmount: string | null;
}

// src/types/payment.ts
export interface AlipayF2FItem {
  body?: string;
  categoriesTree?: string;
  goodsCategory?: string;
  goodsId: string;
  goodsName: string;
  outItemId?: string;
  outSkuId?: string;
  price: string;
  quantity: number;
}

export interface AlipayF2FRequest {
  orderNum: string
  amount: string;
  title: string;
  orderItems: AlipayF2FItem[];
  authCode: string;
}

export interface AlipayF2FResponse {
  success: boolean;
  tradeNo?: string;
  outTradeNo?: string;
  message?: string;
}

// 完整的支付宝支付响应
export interface AlipayF2FResponse extends BasePayResponse {
  data?: {
    alipayTradePayResponse: AlipayTradePayResponse;
    sign: string;                // 签名
  };
}
